package assembler

import (
	"github.com/jinzhu/copier"
	"mine-info-server/domain/plan-manage-context/command"
	"mine-info-server/domain/plan-manage-context/query"
	"mine-info-server/interfaces/request"
)

/*
计划管理-DTO和命令转换器
*/

type PlanManageAssembler struct {
}

// ToCommandFromCreateRequest 创建计划Request转命令
func (p *PlanManageAssembler) ToCommandFromCreateRequest(req *request.CreatePlanRequest) *command.PlanCreateCommand {
	return &command.PlanCreateCommand{
		Name:      req.Name,
		StartTime: req.StartTime,
		EndTime:   req.EndTime,
		ParentId:  req.ParentId,
	}
}

// ToCommandFromDeleteRequest 删除计划Request转命令
func (p *PlanManageAssembler) ToCommandFromDeleteRequest(req *request.IdRequest) *command.PlanDeleteCommand {
	return &command.PlanDeleteCommand{
		PlanId: req.Id,
	}
}

// ToCommandFromEditRequest 编辑计划Request转命令
func (p *PlanManageAssembler) ToCommandFromEditRequest(req *request.EditPlanRequest) *command.PlanEditCommand {
	return &command.PlanEditCommand{
		PlanId:    req.PlanId,
		Name:      req.Name,
		StartTime: req.StartTime,
		EndTime:   req.EndTime,
		ParentId:  req.ParentId,
	}
}

// ToQueryFromGenerateReportRequest 生成计划报告Request转查询
func (p *PlanManageAssembler) ToQueryFromGenerateReportRequest(req *request.GetByPlanId) *query.GeneratePlanReportQuery {
	return &query.GeneratePlanReportQuery{PlanId: req.PlanID}
}

func (p *PlanManageAssembler) ToCommandFromEditTargetRequest(req *request.EditTargetRequest) *command.TargetEditCommand {
	return &command.TargetEditCommand{
		PlanID: req.PlanID,
		Target: req.Target,
	}
}

func (p *PlanManageAssembler) ToQueryFromGetPlanDetailRequest(req *request.GetByPlanId) *query.GetPlanDetailQuery {
	return &query.GetPlanDetailQuery{PlanId: req.PlanID}
}

func (p *PlanManageAssembler) ToQueryFromGetPlanRequest(req *request.GetByPlanId) *query.GetPlanQuery {
	return &query.GetPlanQuery{PlanId: req.PlanID}
}

func (p *PlanManageAssembler) ToQueryFromGetPlanList(req request.PageInfo) *query.GetPlanListQuery {
	return &query.GetPlanListQuery{
		Page:     req.Page,
		PageSize: req.PageSize,
	}
}

func (p *PlanManageAssembler) ToCommandFromSubmitPlanReport(req *request.SubmitPlanReportRequest) *command.PlanReportSubmitCommand {
	res := &command.PlanReportSubmitCommand{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromFindPlanReport(req *request.GetByPlanId) *query.FindPlanReportQuery {
	res := &query.FindPlanReportQuery{PlanId: req.PlanID}
	return res
}

func (p *PlanManageAssembler) ToCommandFromCreateTaskRequest(req *request.CreateTaskRequest) *command.CreateTaskCommand {
	res := &command.CreateTaskCommand{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToCommandFromDeleteTaskItemById(req *request.GetById) *command.DeleteTaskItemCommand {
	return &command.DeleteTaskItemCommand{
		TaskItemId: req.ID,
	}
}

func (p *PlanManageAssembler) ToCommandFromDeleteTaskById(req *request.GetById) *command.DeleteTaskCommand {
	return &command.DeleteTaskCommand{TaskId: req.ID}
}

func (p *PlanManageAssembler) ToQueryFromGetTaskItemById(req *request.GetById) *query.GetTaskItemQuery {
	return &query.GetTaskItemQuery{TaskItemId: req.ID}
}

func (p *PlanManageAssembler) ToQueryFromGetTaskList(req *request.GetTaskListRequest) *query.GetTaskListQuery {
	res := &query.GetTaskListQuery{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToCommandFromEditTaskItem(req *request.EditTaskItemRequest) *command.EditTaskItemCommand {
	res := &command.EditTaskItemCommand{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToCommandFromFinishTaskItem(req *request.GetById) *command.FinishTaskItemCommand {
	return &command.FinishTaskItemCommand{TaskItemId: req.ID}
}

func (p *PlanManageAssembler) ToCommandFromSaveQuestionRequest(req *request.QuestionRequest) *command.SaveQuestionCommand {
	res := &command.SaveQuestionCommand{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromFindOneDayQuestions(req *request.OneDayQuestionRequest) *query.FindOneDayQuestionQuery {
	res := &query.FindOneDayQuestionQuery{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromSearchQuestionRequest(req *request.SearchQuestionsRequest) *query.SearchQuestionQuery {
	res := &query.SearchQuestionQuery{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromGetOngoingTasksRequest(req *request.GetOngoingTasksRequest) *query.GetOngoingTasksQuery {
	res := &query.GetOngoingTasksQuery{}
	copier.Copy(&res, req)
	return res
}

func (p *PlanManageAssembler) ToQueryFromIsFinishTaskRequest(req *request.GetByPlanId) *query.IsFinishTaskQuery {
	res := &query.IsFinishTaskQuery{}
	copier.Copy(&res, req)
	return res
}
